// 问诊相关的共享数据

import type { ConsultType } from "@/enums";
import type { ConsultIllness, PartialConsult } from "@/types/consult";
import { defineStore } from "pinia";
import { ref } from "vue";

// cp    consult patient  患者咨询
export const useConsultStore = defineStore('cp-consult', () => {

  // 定义数据
  const consult = ref<PartialConsult>({})

  // 定义修改数据的方法
  // 因为每到一个页面 就收集一点点信息 所以需要准备挺多修改数据的方法
  // 收集用户到底在首页选择了  问医生1 极速问诊2 开药门诊3    枚举ConsultType
  const setType = (type: ConsultType) => {
    consult.value.type = type
  }

  // 收集用户到底选择了 三甲1 普通0  没有枚举就是联合
  const setIllnessType = (illnessType: 0 | 1) => {
    consult.value.illnessType = illnessType
  }

  // 收集用户选择的科室id
  const setDepId = (depId: string) => {
    consult.value.depId = depId
  }

  // 收集用户的描述 时间 就诊 图片
  // 工具类型 Partial  Required  Pick/Omit  Record
  const setIllness = (obj: ConsultIllness) => {
    consult.value.illnessDesc = obj.illnessDesc
    consult.value.illnessTime = obj.illnessTime
    consult.value.consultFlag = obj.consultFlag
    consult.value.pictures = obj.pictures
  } // setIllness({illnessDesc: '123', illnessTime: 1})

  // 收集患者id
  const setPatientId = (patientId: string) => {
    consult.value.patientId = patientId
  }

  // 收集优惠券id
  const setCouponId = (couponId: string) => {
    consult.value.couponId = couponId
  }

  // 支付完成后 清空数据 方便下次重新问诊
  const clear = () => {
    consult.value = {}
  }

  return {
    consult,
    setType,
    setIllnessType,
    setDepId,
    setIllness,
    setPatientId,
    setCouponId,
    clear
  }
}, {
  persist: true
})
